﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XnaXaml.Controls;

namespace XnaXaml.Xaml
{
    public class XamlRenderer : DrawableGameComponent
    {
        #region Properties

        public SpriteBatch SpriteBatch { get; set; }
        public XamlDocument XamlDocument { get; set; }
        public string XamlAssetName { get; set; }
        public Page LayoutRoot { get; set; }

        #endregion

        #region Constructor

        public XamlRenderer(Game game, string xamlAssetName) : base(game)
        {
            XamlAssetName = xamlAssetName;
        }
        

        #endregion

        #region Methods

        protected override void LoadContent()
        {
            XamlDocument = Game.Content.Load<XamlDocument>(XamlAssetName);
            LayoutRoot = XamlDocument.ToXna();
            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }
        
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                LayoutRoot.Render(this);
            SpriteBatch.End();
        }

        #region Control Generation

        public virtual void GenerateBorder(Border border) { }
        public virtual void GenerateGrid(Grid grid) { }
        public virtual void GeneratePage(Page page) { }
        public virtual void GenerateButton(Button button) { }
        public virtual void GenerateCheckBox(CheckBox checkBox) { }
        public virtual void GenerateComboBox(ComboBox comboBox) { }
        public virtual void GenerateImage(Image image) { }
        public virtual void GenerateLabel(Label label) { }
        public virtual void GenerateListBox(ListBox listBox) { }
        public virtual void GenerateRadioButton(RadioButton radioButton) { }
        public virtual void GenerateStackPanel(StackPanel stackPanel) { }
        public virtual void GenerateTabControl(TabControl tabControl) { }
        public virtual void GenerateTabItem(TabItem tabItem) { }
        public virtual void GenerateTextBlock(TextBlock textBlock) { }
        public virtual void GenerateTextBox(TextBox textBox) { }

        #endregion

        #region Control Rendering

        public virtual void RenderBorder(Border border) { }
        public virtual void RenderGrid(Grid grid) { }
        public virtual void RenderPage(Page page) { }
        public virtual void RenderButton(Button button) { }
        public virtual void RenderCheckBox(CheckBox checkBox) { }
        public virtual void RenderComboBox(ComboBox comboBox) { }
        public virtual void RenderImage(Image image) { }
        public virtual void RenderLabel(Label label) { }
        public virtual void RenderListBox(ListBox listBox) { }
        public virtual void RenderRadioButton(RadioButton radioButton) { }
        public virtual void RenderStackPanel(StackPanel stackPanel) { }
        public virtual void RenderTabControl(TabControl tabControl) { }
        public virtual void RenderTabItem(TabItem tabItem) { }
        public virtual void RenderTextBlock(TextBlock textBlock) { }
        public virtual void RenderTextBox(TextBox textBox) { }

        #endregion

        #endregion
    }
}
